﻿using ActiveStoryTouch.DataModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Runtime.Serialization;
using System.IO;

namespace TestSuite
{
    
    
    /// <summary>
    ///This is a test class for SessionSettingsTest and is intended
    ///to contain all SessionSettingsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SessionSettingsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for SaveToFile
        ///</summary>
        [TestMethod()]
        public void SaveToFileTest()
        {
            SessionSettings target = new SessionSettings { TaskInstructions = "This is a sample task instruction.", InitialPage = 1 };
            string fileName = "SessionSettings.xml";
            target.SaveToFile(fileName);

            DataContractSerializer serializer = new DataContractSerializer(typeof(SessionSettings));
            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            SessionSettings actual = serializer.ReadObject(fileStream) as SessionSettings;
            fileStream.Close();

            Assert.AreEqual<String>(target.TaskInstructions, actual.TaskInstructions);
            Assert.AreEqual<long>(target.InitialPage, actual.InitialPage);
        }

        /// <summary>
        ///A test for LoadFromFile
        ///</summary>
        [TestMethod()]
        public void LoadFromFileTest()
        {
            string fileName = "SessionSettings.xml";
            SessionSettings expected = new SessionSettings { TaskInstructions = "This is a sample task instruction.", InitialPage = 1 };
            DataContractSerializer serializer = new DataContractSerializer(typeof(SessionSettings));
            FileStream fileStream = new FileStream(fileName, FileMode.Create);
            serializer.WriteObject(fileStream, expected);
            fileStream.Flush();
            fileStream.Close();

            SessionSettings actual;
            actual = SessionSettings.LoadFromFile(fileName);
            Assert.AreEqual<long>(expected.InitialPage, actual.InitialPage);
            Assert.AreEqual<String>(expected.TaskInstructions, actual.TaskInstructions);
        }
    }
}
